package jianzhi;

import niuke.TreeNode;

/**
 * description:
 * author:zt
 * date:2021-10-30
 */
//给定一棵二叉搜索树，请找出其中第k大的节点
public class jianzhi54 {
    public int kthLargest(TreeNode root, int k) {
        search(root,k);
        return res;
    }
    int n = 0, res;
    public void search(TreeNode root,int k){
        if (root.right!=null) search(root.right,k);
        n ++;
        if (n == k) {
            res = root.val;
            return;
        }
        if (root.left!=null) search(root.left,k);

    }
}
